import 'package:image/image.dart' as imageProcessing;

class Image {
  String filePath;
  String compressionType; //s:小，m:中,l:大

  Image({
    this.filePath,
    this.compressionType = "s",
  });

  //生成缩略图
  static imageProcessing.Image generateThumbnail(
      imageProcessing.Image image, String compressionType) {
    int weight = 600;
    int height = 600;

    switch (compressionType) {
      case "s":
        {
          if (image.height > 200) {
            height = 200;
            weight = null;
          } else {
            height = null;
            if (image.width > 200) {
              weight = 200;
            } else {
              weight = image.width;
            }
          }
        }
        break;
      case "m":
        {
          if (image.height > 1080) {
            height = 1080;
            weight = null;
          } else {
            height = null;
            if (image.width > 600) {
              weight = 600;
            } else {
              weight = image.width;
            }
          }
        }
        break;

      default:
        {
          weight = 600;
          height = null;
        }
    }
    // Resize the image to a 120x? thumbnail (maintaining the aspect ratio).
    return imageProcessing.copyResize(image, width: weight, height: height);
  }
}
